<template>
    <div class="e-form" >
        <BillTop title="大修计划新增" @cancel="handleClose"></BillTop>
        <div  class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="formData.planRepair" label-width="200px" :rules="rules">
                <el-row>
                    <!-- <el-col :span="12">
                        <el-form-item label="计划编号：">
                            <span>{{ formData.planRepair.billNo }}</span>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="12">
                        <el-form-item label="计划日期：" prop="billDate">
                            <el-date-picker
                                v-model="formData.planRepair.billDate"
                                type="date"
                                placeholder="选择日期"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                                <span>{{ userInfo.orgInfo.orgName}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="计划人：">
                                <span>{{ formData.planRepair.founderName }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="计划维修费（元）：">
                            <span>{{ formData.planRepair.budgetAmount }}</span>
                        </el-form-item>
                    </el-col>
                <el-col :span="12">
                        <el-form-item label="状态：">
                            <span>{{ statusLable(formData.planRepair.state) }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item  label="备注：">
                        <el-input type="textarea" v-model="formData.planRepair.remarks"></el-input>
                    </el-form-item>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                v-debounce
                @click="preserve"
                >保存</el-button
            >
            <el-button size="small" @click="handleClose" v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/equip/equipPlan.js'
import { mapState } from 'vuex'
export default {
    data () {
        return {
            formData: {
                //大修基础信息
                'planRepair': {
                    'auditTime': '',
                    'auditor': '',
                    'auditorId': '',
                    'billDate': '',
                    'billId': '',
                    'billNo': '',
                    'budgetAmount': 0,
                    'changeBillId': '',
                    'changeBillNo': '',
                    'changeBudgetAmount': 0,
                    'changeState': null,
                    'founderId': '',
                    'founderName': '',
                    'modifier': '',
                    'modifierId': '',
                    'nullifyCreated': '',
                    'nullifyCreator': '',
                    'nullifyCreatorId': '',
                    'nullifyDescription': '',
                    'nullifyReason': '',
                    'number': 0,
                    'orgId': '',
                    'orgName': '',
                    'recorder': '',
                    'recorderId': '',
                    'remarks': '',
                    'state': 0,
                    'version': 0,
                    'workId': '',
                    'year': 0
                }
            },
            rules: {
                billDate: [
                    { required: true, message: '请选择日期', trigger: 'blur' },
                ],
            },
        }
    },
    components: {
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
    },
    created () {
        this.getInfo()
    },
    mounted () {
    },
    methods: {
        getInfo () { //默认获取数据
            const date = new Date()
            this.formData.planRepair.billDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
            this.formData.planRepair.founderName = localStorage.getItem('userName')
            this.formData.planRepair.founderId = this.userId
        },
        //保存
        preserve () {
            this.$refs.form.validate(valid => {
                if (valid) {
                    request.majorPlanAdd(this.formData).then(res=>{
                        this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                            this.$router.push({
                                path: '/majorPlanEdit',
                                query: {
                                    billid: res,
                                    name: 'planDetail'
                                }
                            })
                        },
                        null,
                        this.handleClose
                        )
                    })
                } else {
                    return false
                }
            })

        },
        //取消
        handleClose () {
            this.$router.replace('/majorPlanList')
        },
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
